package haltica.com.mx.ape.services.usuarios;

import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.GrantedAuthorityImpl;
import org.springframework.stereotype.Service;

import haltica.com.mx.ape.domain.UserDetailsImpl;
import haltica.com.mx.ape.domain.UsuarioSistema;

@Service("assembler")
public class UserAssembler {
	
	public UserDetailsImpl buildUserFromUsuarioSistema(UsuarioSistema userEntity) {
		
		Collection<GrantedAuthority> authorities;
		UserDetailsImpl userDetails;
		
		authorities = new ArrayList<GrantedAuthority>();
		authorities.add(new GrantedAuthorityImpl(userEntity.getPerfilRole().getDescripcion()));
		
		
		userDetails = new UserDetailsImpl(userEntity.getUsername(),
				userEntity.getPassword(), authorities, userEntity.getEnabled(),
				userEntity);
		
		return userDetails;
	}
}
